package com.itheima.mapper;

import com.itheima.domain.Route;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface RouteMapper {
    @Select("select * from tab_route where cid=#{cid}")
    List<Route> findRouteByCid(Integer cid);

    @Results(
            value = {
                    @Result(column = "rid",property = "rid"),
                    @Result(column = "rname", property = "rname"),
                    @Result(column = "price", property = "price"),
                    @Result(column = "description", property = "description"),
                    @Result(column = "num", property = "num"),
                    @Result(column = "cid", property = "cid"),
                    @Result(column = "rimage", property = "rimage"),
                    @Result(column = "sid", property = "sid"),
                    @Result(column = "cid", property = "category", one = @One(
                            select = "com.itheima.mapper.CategoryMapper.findByCid"
                    )),
                    @Result(column = "sid", property = "seller", one = @One(
                            select = "com.itheima.mapper.SellerMapper.findBySid"
                    )),
                    @Result(column = "rid", property = "routeImgList" ,many = @Many(
                            select = "com.itheima.mapper.RouteImgMapper.findImgByRid"
                    ))
            }
    )
    @Select("select * from tab_route where rid=#{rid}")
    Route findRouteByRid(Integer rid);

}
